{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1ede8c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import h5py\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.image as mpimg\n",
    "import os\n",
    "import os.path as osp\n",
    "import imageio.v2 as imageio\n",
    "\n",
    "from scipy.stats import describe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d7a32e40",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# # Resized hypersim dataset\n",
    "# s = 0\n",
    "# # List of file paths\n",
    "# root = \"/lc/data/3D/resized_hypersim/train/ai_001_001/cam_00\"\n",
    "# file_paths = sorted([f for f in os.listdir(root) if f.endswith(\".png\")])\n",
    "\n",
    "# cols = 3\n",
    "# rows = 5\n",
    "# interval = 1\n",
    "# # Create a figure with 2 columns and 10 rows,dpi=100\n",
    "# fig, axs = plt.subplots(rows, cols, figsize=(12, 15))\n",
    "\n",
    "# # Iterate over the file paths and display the images\n",
    "# for i, file_path in enumerate(file_paths[s:rows*cols*interval+s:interval]):\n",
    "#     img = mpimg.imread(osp.join(root, file_path))\n",
    "#     axs[i // cols, i % cols].imshow(img)\n",
    "#     axs[i // cols, i % cols].axis(\"off\")  # Hide axis ticks\n",
    "#     axs[i // cols, i % cols].set_title(file_path.split('_')[0])\n",
    "\n",
    "# plt.show()\n",
    "# tensor(119.7930, device='cuda:0')\n",
    "# ['ai_013_001/cam_00_000029_rgb.png', 'ai_024_002/cam_00_000082_rgb.png']\n",
    "# tensor(11.6582, device='cuda:0')\n",
    "# ['ai_044_007/cam_01_000056_rgb.png', 'ai_026_009/cam_00_000019_rgb.png', 'ai_038_006/cam_01_000049_rgb.png']\n",
    "# tensor(29.8385, device='cuda:0')\n",
    "# ['ai_026_016/cam_00_000057_rgb.png', 'ai_026_020/cam_00_000022_rgb.png']\n",
    "# tensor(11.4876, device='cuda:0')\n",
    "# ['ai_024_015/cam_00_000007_rgb.png']\n",
    "# tensor(12.8079, device='cuda:0')\n",
    "# ['ai_024_009/cam_00_000078_rgb.png', 'ai_024_008/cam_00_000033_rgb.png']\n",
    "# tensor(9.4288, device='cuda:0')\n",
    "# ['ai_026_013/cam_02_000001_rgb.png']\n",
    "# tensor(8.7087, device='cuda:0')\n",
    "# ['ai_026_007/cam_00_000050_rgb.png']\n",
    "# tensor(8.6912, device='cuda:0')\n",
    "# ['ai_013_003/cam_00_000004_rgb.png']\n",
    "# tensor(5.8992, device='cuda:0')\n",
    "# ['ai_023_009/cam_00_000016_rgb.png']\n",
    "# tensor(8.5143, device='cuda:0')\n",
    "# ['ai_052_005/cam_00_000050_rgb.png']\n",
    "# tensor(10.2802, device='cuda:0')\n",
    "# ['ai_024_007/cam_00_000024_rgb.png', 'ai_027_005/cam_00_000034_rgb.png', 'ai_039_006/cam_00_000067_rgb.png']\n",
    "# tensor(6.7837, device='cuda:0')\n",
    "# ['ai_024_007/cam_01_000038_rgb.png']\n",
    "# tensor(8.2159, device='cuda:0')\n",
    "# ['ai_038_007/cam_00_000046_rgb.png']\n",
    "# tensor(9.0273, device='cuda:0')\n",
    "# ['ai_026_005/cam_00_000053_rgb.png', 'ai_027_005/cam_03_000003_rgb.png']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "adc498a7",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "s = 0\n",
    "# List of file paths\n",
    "root = \"/home/liucong/data/3d/hypersim_processed/train/ai_036_007/cam_00\"\n",
    "file_paths = sorted([f for f in os.listdir(root) if f.endswith(\".png\")])\n",
    "print(len(file_paths))\n",
    "cols = 4\n",
    "rows = 6\n",
    "interval = 5\n",
    "# Create a figure with 2 columns and 10 rows,dpi=100\n",
    "fig, axs = plt.subplots(rows, cols, figsize=(12, rows*2))\n",
    "\n",
    "# Iterate over the file paths and display the images\n",
    "for i, file_path in enumerate(file_paths[s:rows*cols*interval//2+s:interval]):\n",
    "    img = mpimg.imread(osp.join(root, file_path))\n",
    "    depth_f = file_path.split('_')[0] + '_depth.npy'\n",
    "    depth = np.load(osp.join(root, depth_f))\n",
    "    depth[~np.isfinite(depth)] = 0\n",
    "    desc = f'{depth.min():2f}, {depth.max():2f}, {depth.mean():2f}'\n",
    "    axs[i * 2 // cols , i * 2 % cols ].imshow(img)\n",
    "    axs[i * 2 // cols , i * 2 % cols].axis(\"off\")  # Hide axis ticks\n",
    "    # axs[i * 2 // cols , i * 2 % cols].set_title(file_path.split('_')[0]+f\"_{i}\")\n",
    "    axs[i * 2 // cols , i * 2 % cols + 1].imshow(depth)\n",
    "    axs[i * 2 // cols , i * 2 % cols + 1].axis(\"off\")  # Hide axis ticks\n",
    "    axs[i * 2 // cols , i * 2 % cols + 1].set_title(desc)\n",
    "\n",
    "plt.show()\n",
    "# totally correct"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c25e8842",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e6d3162",
   "metadata": {},
   "outputs": [],
   "source": [
    "file_path = file_paths[0]\n",
    "img = mpimg.imread(osp.join(root, file_path))\n",
    "print(img.shape)\n",
    "cam_f = file_path.split('_')[0] + '_cam.npz'\n",
    "cam = np.load(osp.join(root, cam_f))\n",
    "print(\"intrinsics\", cam['intrinsics'].shape)\n",
    "print(cam['intrinsics'])\n",
    "print(\"pose\", cam['pose'].shape)\n",
    "print(cam['pose'])\n",
    "\n",
    "depth_f = file_path.split('_')[0] + '_depth.npy'\n",
    "depth = np.load(osp.join(root, depth_f))\n",
    "print(depth.shape) \n",
    "print(describe(depth, axis=None))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dd801228",
   "metadata": {},
   "source": [
    "(512, 682, 3)\n",
    "intrinsics (3, 3)\n",
    "[[591.20667  -0.      340.83334]\n",
    " [  0.      591.20667 255.83334]\n",
    " [  0.        0.        1.     ]]\n",
    "pose (4, 4)\n",
    "[[ 0.74119383  0.35118043 -0.5721054   2.6220133 ]\n",
    " [ 0.57940215  0.09571245  0.8093997  -2.9775693 ]\n",
    " [ 0.3390023  -0.9314028  -0.13253269  1.582464  ]\n",
    " [ 0.          0.          0.          1.        ]]\n",
    "(512, 682)\n",
    "DescribeResult(nobs=349184, minmax=(np.float32(1.5623133), np.float32(4.1846538)), mean=np.float32(3.1307194), variance=np.float64(0.2473416706327), skewness=np.float64(-0.12327156215906143), kurtosis=np.float32(-0.28179646))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "vggt",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
